<template>
	<view class="container-main">
		<uv-skeletons :loading="skeletonShow" :skeleton="skeletonStyle">
			<view class="container">
				<tui-navigation-bar @init="initNavigation" backgroundColor="#fff" color="#333">
					<view class="tui-header" :style="{ marginTop: navBarTop + 'px' }">
						<!-- 状态栏 -->
						<view class="status-bar"> </view>
						<!-- logo & 搜索 -->
						<view class="top-bar">
							<view class="logo"></view>
							<!-- 定位 -->
							<view class="location-wrapper" @tap.stop.prevent="getLocation()">
								{{ CityName }}
							</view>
						</view>
					</view>
				</tui-navigation-bar>
				<mescroll-body @init="mescrollInit" @down="refresherrefresh" @up="scrolltolower" topbar :isOptUp="false" :headerStyle="headerStyle" mescrollDy
					:up="upOption" bottom="130rpx" :bottombar="false" :top="headerHeight" :down="mescrollDown" :safearea="true">
					<view class="mescroll-body-main" @touchend="inTouchend" @touchstart="inTouchstart">
						<topic :topicList="topicList"></topic>
						<!-- 陪玩类目tab -->
						<view class="category-tab" id="tab" :style="{ '--header-height': headerHeight, '--header-height-f': '-' + headerHeight }"
							:class="{ 'isFixed': isFixed }">
							<tabs v-if="CategoryList.list.length > 1" @click="onCategory" keyName="categoryName" :list="CategoryList.list" itemStyle="auto">
							</tabs>
						</view>
						<view class="main">
							<view class="appraise-list" v-if="postList.list.length > 0">
								<template v-for="(item, index) in postList.list">
									<view class="appraise-item" :key="item.id" :class="{ 'noBorder': index == postList.list.length - 1 }" v-if="item.isShow">
										<post-item :size="'90rpx'" from="index" :post_type="item.forumType" :basicsWidth="widthrpx" :post="item"
											@clickHead="clickHead" @share="share" @comment="comment" @previewImg="previewImg">
											<view v-if="item.forumType == 0" class="refer-box">
												<view class="refer">提到了：</view>
												<view class="order" @tap.stop.prevent="clickHead(item.forumOrder)" v-if="item.forumOrder">
													<view class="accompany-profile">
														<image class="avatarUrl" :src="item.forumOrder.avatar" mode="aspectFill">
														</image>
													</view>
													<view class="user-name onelist-hidden">
														{{ item.forumOrder.nickName }}
													</view>
												</view>
											</view>
										</post-item>
										<view class="advertising" v-if="index == 1 && false" @tap.stop.prevent="lookOver(isBuy)">
											<image class="adv-image"
												src="https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/free-purchase/go.png">
											</image>
										</view>
									</view>
								</template>
							</view>
							<view v-show="postList.loading && postList.list.length <= 0">
								<empty></empty>
							</view>
							<view v-show="load.loading">
								<uv-load-more :status="load.status" :loading-text="load.loadingText" :nomore-text="load.nomoreText"
									:line="load.status == 'nomore'" />
							</view>
						</view>
					</view>
				</mescroll-body>
			</view>
			<button v-if="userInfo.settleState == 1" class="btn-primary btn-submit" :class="{ 'can-swip-submit': canSwip }"
				@tap.stop.prevent="goPage('/page_community/send/send')">🎉发动态</button>
			<!-- 0元购 -->
			<expansion v-if="false" ref="expansion" :inviteList="couponDetail && couponDetail.inflationList || []"></expansion>
			<!-- 顶部弹窗 -->
			<movable-area-top v-if="false" :freePurchase="freePurchase" :isBuy="isBuy"></movable-area-top>
			<!-- 侧边悬浮 红包 -->
			<movable-area-block v-if="false" :iseEnsconce="ensconce" :canSwip="canSwip" :isBuy="isBuy" @tapMovable="tapMovableHB(isBuy)">
				<view class="image-box">
					<view class="free-index-ani">
						<image class="jump1" src="https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/free-purchase/jump3.png">
						</image>
						<image class="jump2" src="https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/free-purchase/jump2.png">
						</image>
						<image class="jump3" src="https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/free-purchase/jump1.png">
						</image>
						<image class="jump4" src="https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/free-purchase/jump4.png">
						</image>
					</view>
					<image class="free-index-btn" src="https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/free-purchase/free-index-btn.png">
					</image>
					<image class="free-index" src="https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/free-purchase/free-index.png">
					</image>
				</view>
			</movable-area-block>
			<!-- 侧边悬浮 入驻 -->
			<movable-area-block v-if="userInfo.settleState != 1" :iseEnsconce="ensconce" :canSwip="canSwip" status="ruzhu"
				@tapMovable="tapMovableRZ('page_account/autonym/index')">
				<view class="image-box">
					<image class="ruzhu-index-btn" src="https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/index/ruzhu.png">
					</image>
				</view>
			</movable-area-block>
		</uv-skeletons>
		<!-- 评论列表 -->
		<uv-popup ref="popup" bgColor="none" mode="bottom" zIndex="2580" :overlayOpacity="0.4">
			<view class="popup-comment">
				<view class="header">
					<view class="title">评论({{ replyNum }}条)</view>
					<view class="close" @tap="closePop"><text class="dy-iconfont icon-a-bianzu69"></text>
					</view>
				</view>
				<!-- -- 评论列表 -- -->
				<comment ref="comment" :list="commentList.list" @onInfo="onInfo" scroll :commentInfo="commentInfo" @scrolltolower="commentScrolltolower"
					:commentLoad="commentLoad" @getMore="getMore" @longpressHandler="longpressHandler" @removeResolve="removeResolve"></comment>
				<view class="foot">
					<view class="foot-box">
						<view class="foot-input">
							<text @tap.stop.prevent="tapInput" class="input-text">{{ inputText || '说点什么…' }}</text>
							<text @tap.stop.prevent="tapEmoji" class="dy-iconfont icon-xingzhuangjiehebeifen"></text>
						</view>
					</view>
				</view>
			</view>
		</uv-popup>
		<!-- 评论 功能弹窗 -->
		<uv-popup :safeAreaInsetBottom="false" ref="popupmenu" mode="bottom" round="20" zIndex="2582">
			<view class="delete-pop-menu">
				<view class="menu-list" :class="{ 'delete': item.lable == 'delete' }" v-for="(item, index) in commentMenuList" :key="item.lable"
					@tap.stop.prevent="selectCommentMenu(item)">
					<view>{{ item.name }}</view>
				</view>
			</view>
		</uv-popup>
		<!-- 0元购 弹窗 -->
		<uv-popup v-if="false" ref="freePurchasePop" bgColor="none" overlayOpacity="0.7" zIndex="2591" @change="freePurchasePopchange">
			<view class="free-purchase-pop">
				<view class="title">
					<view class="title1">您有一份</view>
					<view class="title2"><text style="font-size: 60rpx;">0元购</text> <text>权益待查收</text></view>
				</view>
				<view class="purchase-con"></view>
				<view class="purchase-btn" @tap.stop.prevent="lookOver(isBuy)">
					<view class="rule">查看规则</view>
					<view class="purchase-now" @tap.stop.prevent="payment">
						<view class="ttt">评价后返回</view>
					</view>
				</view>
				<view class="count-down">距活动截止 {{ freePurchase }}</view>
				<view class="free-purchase-pop-close" @tap.stop.prevent="freePurchaseClose">
					<text class="dy-iconfont icon-a-bianzu69"></text>
				</view>
			</view>
		</uv-popup>
		<!-- 海报 -->
		<l-painter ref="painter" hidden />
		<!-- 提示 -->
		<uv-toast ref="toast"></uv-toast>
		<!-- 评论弹窗底部 -->
		<comment-foot ref="commentFoot" :list="commentList.list" @onReply="onReply" @changinput="changinput" @footInputClose="footInputClose"
			:placeholder="placeholder"></comment-foot>
		<!-- #ifdef MP -->
		<!-- 引导关注 -->
		<addition-MP></addition-MP>
		<!-- #endif -->
		<!-- 问卷 -->
		<survey-pop></survey-pop>
		<!-- tabber -->
		<tabbar :current="tabbarCurrent" backdropFilter :tabBar="tabBar" @dblclick="dblclick"></tabbar>
	</view>
</template>

<script>
	import mp from "@/mixins/mp.js";
	import skeleton from "@/utils/skeletonStyle.js";
	import banner from '@/components/banner/banner.vue';
	import tabs from '@/uni_modules/uv-tabs/components/uv-tabs/uv-tabs-index.vue';
	import tabbar from '@/components/custom-tabbar/custom-tabbar.vue';
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import movableAreaBlock from "@/components/movable-area-block/movable-area-block.vue";
	import throttle from '@/uni_modules/uv-ui-tools/libs/function/throttle.js';
	import topic from "./topic.vue";
	import expansion from '@/components/expansion-red-envelope/view.vue';

	const app = getApp();

	export default {
		mixins: [mp, MescrollMixin],
		options: {
			styleIsolation: 'shared'
		}, //解决/deep/不生效**
		components: {
			banner,
			tabs,
			tabbar,
			topic,
			movableAreaBlock,
			expansion
		},
		data() {
			return {
				tabbarCurrent: 0, //当前索引
				tabBar: app.globalData.tabBar,
				navBarOpacity: 0, //标题图标距离顶部距离
				scrollTop: 0.5,
				navBarTop: 0,
				CityName: '全部城市',
				area: '余杭区',
				city: '杭州市',
				CityId: '',
				userLatitude: '',
				userLongitude: '',
				skeletonShow: true,
				load: {
					loading: false,
					status: 'loading',
					loadingText: '努力加载中',
					nomoreText: '没有更多了'
				},
				// 轮播
				bannerList: [],
				CategoryList: {
					list: [{
						id: 0,
						categoryName: '全部',
						categoryIcon: 'https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/temporary/all.png'
					}],
					current: 0,
					id: 0
				},
				postList: {
					list: [],
					hasMore: false,
					loading: false,
					page: 1,
				},
				getLocatStatus: false,
				skeletonStyle: skeleton.index2,
				tempHeight: 0,
				headerStyle: {},
				cityList: [],

				mescrollDown: {
					offset: 60,
					auto: false,
				},
				upOption: {
					auto: false,
					// isBounce: true,
					toTop: {
						src: '' // 不显示回到顶部按钮
					}
				},

				commentList: {
					list: [],
					hasMore: false,
					loading: false,
					page: 1,
				},
				inputText: '',
				placeholder: '说点什么...',
				commentLoad: {
					loading: false,
					status: 'loading',
					loadingText: '努力加载中',
					nomoreText: '没有更多了'
				},
				commentMenuList: [{
					name: '复制评论',
					lable: 'copy'
				}],
				longpressInfo: null,

				widthrpx: 0,
				rpx: app.globalData.widthPx / 750,
				topicList: [],

				couponDetail: {},
				isBuy: 0,

				replyNum: 0,
				shareItem: null,
				commentInfo: null,
				replyinfo: null,
				replyIndex: 0,
				loading: false,
				userInfo: {
					settleState: 0
				},
				postPath: '',
				canSwip: false,
				ensconce: false,
				touchstart: false,
				isFixed: false,
				navTop: 0,
				// 0元购
				freePurchaseTimer: null,
				freePurchase: '00:00:00',

				codeTimer: null, //定时器
				codeTime: 14, // 限制1分钟后没请求到erp数据，不再继续请求
			};
		},
		onShareAppMessage: function(res) {
			const that = this;
			let title = 'PENG一下，趣收获'
			let desc = 'PENG一下，趣收获'
			let path = '/pages/index/index'
			// let imageUrl = 'https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/share/share-1.png'
			if (res.from === 'button') {
				path = '/pages/index/index?invite_code=' + that.userInfo.authInfo.userId
			}
			//转发参数
			return {
				// 转发的标题
				title: title,
				desc: desc,
				path: path,
				//自定义图片路径，可以是本地文件路径、代码包文件路径或者网络图片路径，
				//支持PNG及JPG，不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
				// imageUrl: imageUrl
			}
		},
		/**
		 * 计算属性
		 */
		computed: {
			headerHeight() {
				return app.globalData.topBar.statusBarHeight + 44 + 'px'
			},
		},
		onReady() {
			let freePurchase = uni.getStorageSync('free-purchase') ? uni.getStorageSync('free-purchase') : null;
			setTimeout(() => {
				if (!this.navTop) this.setNavTop()
				if (!freePurchase && this.isBuy != 1) this.$refs.freePurchasePop?.open();
			}, 500)
		},
		onLoad(options) {
			if (options.invite_code) {
				uni.setStorageSync('invite_code', options.invite_code);
			}
			//加载页面数据
			this.getPageData();
			console.log(app.globalData.isLogin);
			if (app.globalData.isLogin) {
				this.loginBindWx()
			}
		},
		onShow: function() {
			uni.hideTabBar()
			// this.x = app.globalData.systemInfo.windowWidth
			this.widthrpx = app.globalData.systemInfo.windowWidth / this.rpx - 32 * 2 - 106
			this.userInfo = uni.getStorageSync('user_info') ? uni.getStorageSync('user_info') : {};
			this.couponDetail = uni.getStorageSync('coupon_detail') ? uni.getStorageSync('coupon_detail') : null;
			if (this.couponDetail && this.couponDetail.userCouponId) {
				this.isBuy = 1
			}
			this.freePurchaseTimer = setInterval(() => {
				this.freePurchase = app.get_date()
			}, 1000)
			app.globalData.tabBar[0].name = 'home'
		},
		onHide() {
			uni.$off('add')
			// uni.$off('selectArea')
		},
		/**
		 * 下拉
		 */
		onPullDownRefresh: function() {},
		/**
		 * 触底
		 */
		onReachBottom() {},
		/**
		 * 滚动
		 */
		onPageScroll(res) {
			const that = this;
			that.scrollTop = parseInt(res.scrollTop);
			let isFixed = that.scrollTop >= that.navTop;
			if (that.isFixed !== isFixed) {
				that.setData({
					isFixed
				})
			}
			that.canSwip = true;
			if (that.touchstart) {
				that.ensconce = true
			}
			clearTimeout(that.timerScroll) // 每次滚动前 清除一次
			that.timerScroll = setTimeout(function() {
				that.canSwip = false;
				that.ensconce = false
			}, 500);
		},
		filters: {
			distance(value) {
				let new_value = Math.floor(value * 100) / 100;
				let new_distance = new_value * 1000
				if (value > 1) {
					return new_value + "km"
				} else if (value < 1 && new_distance > 100) {
					return new_distance + "m"
				} else {
					return '<100m'
				}
			}
		},

		methods: {
			//初始化导航栏
			initNavigation(e) {
				this.navBarOpacity = e.opacity;
				this.navBarTop = e.top;
			},

			// 加载页面数据
			getPageData: function(callback) {
				Promise.all([this.requestPageBanner(), this.getLocat(), this.requestPengList(), this
					.requestTopicList()
				]).then(() => {
					this.skeletonShow = false;
					uni.stopPullDownRefresh();
					callback && callback()
					// this.$refs.popup.open();
				}).catch(() => {
					callback && callback()
				});
			},
			loginBindWx() {
				app._post_form("/client/getById", null, (res) => {
					let user_info = uni.getStorageSync('user_info');
					user_info.settleState = res.data.settleState
					user_info.wechatNumber = res.data.wechatNumber
					uni.setStorageSync('user_info', user_info);
					app.globalData.UserInfo = user_info
					app.globalData.isLogin = !!user_info

					this.$store.commit("changeBindWx", !!res.data.wechatNumber);
				}, false, () => {})
			},
			inTouchstart() {
				this.touchstart = true
			},
			inTouchend() {
				if (this.canSwip == false) {
					this.ensconce = false
				}
				this.touchstart = false
			},
			dblclick() {
				this.mescroll.scrollTo(0, 300); // 执行回到顶部
				setTimeout(() => {
					this.mescroll.triggerDownScroll()
				}, 300)
			},
			goPage(url) {
				uni.navigateTo({
					url: url,
				});
			},
			//话题
			requestTopicList() {
				return new Promise((resolve, reject) => {
					app._get('/client/forum-topic/topic-list', null, (result) => {
						this.topicList = result.data
						resolve()
					}, null, (err) => {})
				})
			},
			// banner && 类目
			requestPageBanner() {
				return new Promise((resolve, reject) => {
					app._post_form(
						"/client/index/banner", null,
						(result) => {
							let data = result.data
							data.indexCategoryList.forEach((item, index) => {
								this.$set(this.CategoryList.list, index + 1, item)
							})
							data.indexBannerList.forEach((item, index) => {
								this.$set(this.bannerList, index, item)
								this.$set(this.bannerList[index], 'id', index + 1)
							})
							this.bannerList = this.bannerList.sort((a, b) => {
								return a.sortValue - b.sortValue
							})
						}, null, () => {
							resolve();
						}
					);
				});
			},
			clickHead(e) {
				app.navigationTo('page_sharing/accompany/details?id=' + e.userId + '&from=1')
			},
			lookOver(buy) {
				uni.navigateTo({
					url: '/page_account/advertising/advertising?isBuy=' + buy
				})
			},
			onCategory(item) {
				if (this.CategoryList.id != item.id) {
					this.CategoryList.id = item.id
					// this.mescroll.resetUpScroll()
					this.postList.page = 1
					this.load.loading = false
					this.requestPengList()
					this.mescroll.scrollTo(0, 100); // 执行回到顶部
				}
			},
			scroll(e) {
				this.scrollTop = e.detail.scrollTop;
			},
			scrolltolower() {
				if (this.postList.hasMore && this.postList.loading) {
					this.load.loading = true
					this.requestPengList().then((res) => {
						this.mescroll.endSuccess(res.records, res.hasMore);
					});
				}
			},
			refresherrefresh() {
				this.postList.page = 1
				this.getPageData(() => {
					setTimeout(() => {
						this.mescroll.endSuccess();
					}, 500)
				});
			},
			freePurchasePopchange(e) {
				if (e.show) {
					uni.setStorageSync('free-purchase', 'free-purchase');
				}
			},
			freePurchaseClose() {
				this.$refs.freePurchasePop.close();
			},
			setNavTop() {
				let view = uni.createSelectorQuery().select('#tab');
				view.boundingClientRect(data => {
					if (!data) return false
					this.navTop = parseInt(data.top - data.height - app.globalData.topBar.statusBarHeight) // 到屏幕顶部的距离
				}).exec();
			},
			// 动态列表查询
			requestPengList() {
				return new Promise((resolve, reject) => {
					this.postList.loading = false
					let url = '/client/forum-topic/topic-page'
					let paramer = {
						current: this.postList.page,
						extra: {},
						model: {
							forumType: 1,
							categoryId: this.CategoryList.id != 0 ? this.CategoryList.id : null,
							cityId: this.CityId ? this.CityId : null,
							topicId: null
						},
						order: "descending",
						size: 10,
						sort: "createTime"
					}
					app._post_form(url, paramer,
						(result) => {
							let {
								records,
								total
							} = result.data;
							let {
								page,
								list,
								hasMore
							} = this.postList;
							if (1 == page) {
								list.length = 0;
							}
							records.forEach(item => {
								item.animation = false
								item.vanish_animation = false
								item.isZan = false
								item.isShow = !(list.some((it1) => item.id == it1.id))
							})



							list = [...list, ...records];
							hasMore = total > list.length;
							this.postList.hasMore = hasMore;

							this.postList.list = list;
							if (hasMore) {
								page++;
								this.load.loading = false
							} else if (list.length > 3) {
								this.load.loading = true
								this.load.status = 'nomore'
							} else {
								this.load.status = 'nomore'
							}
							resolve({
								records: records.length,
								hasMore
							});
							this.postList.page = page;
						}, () => {
							this.mescroll.endErr();
						}, () => {
							reject();
							this.postList.loading = true
						}
					);
				});
			},
			// 0元购支付 --------------------------------------
			getCoupon() {
				return new Promise((resolve, reject) => {
					app._get(
						"/client/coupon/query/coupon-toast", null,
						(result) => {
							let res = result.data
							resolve(res);
						}, null, () => {
							resolve(false);
						}
					);
				});
			},

			async getCouponDetail() {
				let that = this
				const result = await that.getCoupon()
				return new Promise((resolve, reject) => {
					app._post_form(
						"/client/coupon/query/coupon-detail", result.couponId,
						(result) => {
							uni.setStorageSync('coupon_detail', result.data);
							app.globalData.couponDetail = result.data
							that.$refs.toast.hide()
							that.freePurchaseClose()
							// that.lookOver(1)
							resolve(result);
						}, null, () => {
							resolve(false);
						}
					);
				});
			},

			payState(id) {
				let that = this
				return new Promise((resolve, reject) => {
					app._post_form(
						"/client/order/query/pay-state", id,
						(result) => {
							console.log('支付结果', result);
							that.$refs.toast.hide()
							if (result.data.payState != 0) {
								that._clearCount()
								// this.getCouponDetail()
								this.$refs.expansion.openPop()
							}
							resolve(result);
						}, () => {
							that.$refs.toast.hide()
							that._clearCount()
						}, null, () => {
							that.$refs.toast.hide()
							that._clearCount()
						}
					);
				});
			},
			_codeCount(id) {
				let that = this
				that.$refs.toast.show({
					type: 'loading',
				})

				that.codeTimer = setInterval(() => {
					if (that.codeTime <= 0) {
						clearInterval(that.codeTimer);
						that.codeTimer = null;
						that.codeTime = 0;
						that.$refs.toast.hide()
						/* 清除定时的逻辑*/
					} else {
						/*未请求到接口，继续请求数据*/
						that.payState(id)
						that.codeTime--;
					}
				}, 2000);
			},
			//清除定时器
			_clearCount() {
				clearInterval(this.codeTimer);
				this.codeTimer = null;
				this.codeTime = 0;
			},

			saveReserve(params) {
				return new Promise((resolve, reject) => {
					app._post_form(
						"/client/coupon/submit/coupon-order", params,
						(result) => {
							resolve(result);
						}, null, () => {
							reject();
						}
					);
				});
			},
			payment() {
				let that = this
				if (!that.couponDetail) {
					app.doLogin()
					return
				}
				console.log('--------------');
				if (that.isBuy == 1) {
					that.lookOver(1)
					return
				}
				that.$refs.toast.show({
					type: 'loading',
				})
				let provider = uni.getProvider({
					service: 'payment'
				})
				that.saveReserve(that.couponDetail.couponId).then(res => {
					that.$refs.toast.hide()
					let data = res.data
					// res为调起微信支付所需参数
					// 调起微信支付
					uni.requestPayment({
						provider: 'wxpay', // 服务提提供商
						appId: data.appId,
						timeStamp: data.timeStamp, // 时间戳
						nonceStr: data.nonceStr, // 随机字符串
						package: data.prepayId,
						signType: data.signType, // 签名算法
						paySign: data.paySign, // 签名
						success: function(res) {
							console.log('支付成功', res);
							// 业务逻辑。。。
							that._codeCount(data.orderId)
						},
						fail: function(err) {
							console.log('支付失败', err);
						}
					});
				}).catch(err => {
					that.$refs.toast.hide()
					console.log(err);
				})
			},

			//  ------------------------------------------------------------
			previewImg(e) {
				return new Promise((resolve, reject) => {
					app._post_form("/client/forum-topic/submit-forum-view", {
							"list": [{
								"forumId": e.id,
								"topicId": e.topicId
							}]
						},
						(result) => {
							resolve();
						}, null, () => {
							reject();
						}
					);
				});
			},

			// 分享开始 ----------------------------------
			getShareCode(id) {
				return new Promise((resolve, reject) => {
					app._post_form(
						"/client/qr/create-wx-code", {
							envVersion: 'release',
							forumId: id,
							path: "page_community/details/details?id=" + id + '&from=share',
						},
						(result) => {
							let res = result.data
							resolve(res);
						}, null, () => {
							resolve(false);
						}
					);
				});
			},

			async share(e) {
				let that = this
				that.$refs.toast.show({
					type: 'loading',
				})
				const shareCode = await that.getShareCode(e.id)
				that.mp.poster.views[1].views[0].src = e.avatar
				that.mp.poster.views[1].views[1].text = e.nickName
				that.mp.poster.views[1].views[3].text = e.cityName
				that.mp.poster.views[2].views[0].text = e.content
				that.mp.poster.views[3].views[0].src = shareCode.url

				if (!e.forumPictureList) {
					that.mp.poster.css.height = "462rpx"
					that.mp.poster.css.padding = "56rpx 47rpx 16rpx 38rpx"
					that.mp.poster.css.backgroundImage =
						'url("https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/community/poser-bg-w2.png")'
					that.mp.poster.views[0].css.width = "0"
					that.mp.poster.views[0].css.height = "0"
					that.mp.poster.views[0].css.marginBottom = "0"
					that.mp.poster.views[1].css.marginBottom = "50rpx"
				} else {
					that.mp.poster.css.height = "1039rpx"
					that.mp.poster.css.padding = "64rpx 38rpx 16rpx 38rpx"
					that.mp.poster.css.backgroundImage =
						'url("https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/community/poser-bg-h2.png")'
					that.mp.poster.views[0].css.width = "576rpx"
					that.mp.poster.views[0].css.height = "576rpx"
					that.mp.poster.views[0].css.marginBottom = "46rpx"
					that.mp.poster.views[0].src = e.forumPictureList[0].coverPictureUrl ? e.forumPictureList[0]
						.coverPictureUrl : e.forumPictureList[0].fileUrl
				}
				// 渲染
				that.$refs.painter.render(that.mp.poster);
				// 生成图片
				that.$refs.painter.canvasToTempFilePathSync({
					fileType: "jpg",
					// 如果返回的是base64是无法使用 saveImageToPhotosAlbum，需要设置 pathType为url
					pathType: 'url',
					quality: 1,
					success: (res) => {
						that.$refs.toast.hide()
						wx.showShareImageMenu({
							path: res.tempFilePath,
							success: () => {},
						})
					},
					fail: () => {
						that.$refs.toast.hide()
					}
				});
			},
			// 分享结束 ----------------------------------

			// 评价开始 ------------------------------------------------------------

			// 长按
			longpressHandler(e) {
				this.longpressInfo = e
				if (e.delete_status) {
					this.$set(this.commentMenuList, 1, {
						name: '删除',
						lable: 'delete'
					})
				} else {
					this.commentMenuList.splice(1, 1)
				}
				this.$refs.popupmenu.open();
			},
			selectCommentMenu(item) {
				let that = this
				if (item.lable == 'copy') {
					uni.setClipboardData({
						data: that.longpressInfo.item.comment,
						showToast: false,
						success: function() {
							that.$refs.popupmenu.close();
							that.$refs.toast.show({
								type: 'default',
								message: "复制成功"
							})
							setTimeout(() => {
								that.$refs.toast.hide()
							}, 1000)
						}
					});
				} else if (item.lable == 'delete') {
					that.$refs.popupmenu.close();
					that.$refs.comment.deleteComment()
				}
			},
			removeResolve() {
				let that = this
				that.$refs.toast.show({
					type: 'default',
					message: "删除成功"
				})
				setTimeout(() => {
					that.$refs.toast.hide()
				}, 1000)
			},
			// 长按结束 --------

			commentScrolltolower() {
				if (this.commentList.hasMore && !this.commentList.loading) {
					this.commentLoad.loading = true
					this.getCommentList()
				}
			},
			// 子评论列表查询
			getMore(e) {
				this.$set(this.commentList.list[e.index], 'clientForumCommentPage', e)
			},

			// 评论列表查询
			getCommentList(id) {
				return new Promise((resolve, reject) => {
					this.commentList.loading = false
					app._post_form("/client/forum-comment/query-page", {
							current: this.commentList.page,
							extra: {},
							model: {
								forumId: this.commentInfo.id,
							},
							order: "descending",
							size: 10,
							sort: "createTime"
						},
						(result) => {
							let {
								records,
								total
							} = result.data;
							let {
								page,
								list,
								hasMore
							} = this.commentList;
							if (1 == page) {
								list.length = 0;
							}
							records.forEach((item, index) => {
								item.clientForumCommentPage = {
									list: item.clientForumCommentPageVO ? [item
										.clientForumCommentPageVO
									] : [],
									hasMore: item.commentNum > 1 ? true : false,
									loading: false,
									page: 1,
									index: 0
								}
							})

							list = [...list, ...records];
							hasMore = total > list.length;
							console.log(list);
							if (hasMore) {
								page++;
								this.commentLoad.loading = false
							} else if (list.length > 3) {
								this.commentLoad.loading = true
								this.commentLoad.status = 'nomore'
							} else {
								this.commentLoad.status = 'nomore'
							}
							this.commentList.hasMore = hasMore;
							this.commentList.list = list;
							this.commentList.page = page;
							resolve();
						}, null, () => {
							reject();
						}
					);
				});
			},

			// 评价列表&&弹窗
			comment(e) {
				let that = this
				that.$refs.toast.show({
					type: 'loading',
				})
				that.commentList = {
					list: [],
					hasMore: false,
					loading: false,
					page: 1,
				}
				that.replyNum = e.forumCommentNum
				that.commentInfo = e
				that.getCommentList(e.id).then(() => {
					that.$refs.toast.hide()
					that.$refs.popup.open();
					that.placeholder = '说点什么...'
				}).catch(() => {
					that.$refs.toast.hide()
				})
			},
			// 关闭评价列表弹窗
			closePop() {
				this.$refs.popup.close();
			},
			// 点表情
			tapEmoji() {
				this.replyinfo = this.commentInfo
				this.$refs.commentFoot.tapEmoji();
			},
			// 点输入框block
			tapInput() {
				this.replyinfo = this.commentInfo
				this.$refs.commentFoot.tapInput();
			},
			// 点用户回复
			onInfo(e) {
				if (e.index) {
					this.replyIndex = e.index
				}
				this.replyinfo = e.item
				this.placeholder = '回复@' + e.item.userName
				this.$refs.commentFoot.tapInput();
			},
			// 用户输入
			changinput(e) {
				this.inputText = e
			},
			// 输入框弹窗关闭
			footInputClose() {
				if (!this.inputText) {
					setTimeout(() => {
						this.placeholder = '说点什么...'
					}, 200)
				}
			},
			// 回复内容校验
			validMessages(str) {
				var re = /\S/
				return re.test(str)
			},
			// 回复
			onReply(e) {
				let that = this
				if (!that.validMessages(that.inputText)) {
					that.$refs.toast.show({
						type: 'default',
						message: "请输入回复内容"
					})
					setTimeout(() => {
						that.$refs.toast.hide()
					}, 1000)
					return
				}
				if (!e) {
					that.$refs.toast.show({
						type: 'default',
						message: "输入文字不合法"
					})
					setTimeout(() => {
						that.$refs.toast.hide()
					}, 1000)
					return
				}
				throttle(app._post_form('/client/forum-topic/submit-comment', {
					comment: that.inputText,
					commentType: that.replyinfo.type == 'comment' ? 0 : 1,
					forumId: that.replyinfo.type == 'comment' ? that.replyinfo.forumId : that.replyinfo.id,
					commentId: that.replyinfo.type == 'comment' ? that.replyinfo.commentId : null,
				}, (result) => {
					let data = Object.assign(result.data, {
						clientForumCommentPage: {
							list: [],
							hasMore: true,
							loading: false,
							page: 1,
							index: 0
						}
					})
					that.inputText = ''
					that.$refs.commentFoot.changinputSec()
					uni.hideKeyboard();
					that.$refs.toast.show({
						type: 'default',
						message: "评论成功"
					})
					setTimeout(() => {
						that.$refs.toast.hide()
					}, 1000)
					if (that.replyinfo.type == 'post') {
						data.commentNum = 0
						that.replyNum = Number(that.replyNum) + 1
						that.$refs.comment.goTop()
						that.commentList.list.unshift(data)
					} else {
						that.replyNum = Number(that.replyNum) + 1
						that.$refs.comment.onReplyChild(data)
					}
				}, null, (err) => {
					that.inputText = ''
					that.$refs.commentFoot.changinputSec()
				}), 1000, true)
			},
			// 评价结束 ------------------------------------------------------------

			// 获取地理位置
			async getLocat() {
				let _that = this;
				uni.$on('selectAreaCommunity', function(data) {
					_that.CityName = data.city
					_that.CityId = data.id
					_that.city = data.city
					_that.area = data.area
					_that.postList.list = [];
					_that.postList.page = 1
					_that.requestPengList()
					return
				})
			},

			getLocation() {
				uni.navigateTo({
					url: '/pages/index/location?from=community'
				})
			},
			tapMovableHB(buy) {
				uni.navigateTo({
					url: '/page_account/advertising/advertising?isBuy=' + buy
				})
			},
			onCheckLogin() {
				if (!app.globalData.isLogin) {
					app.doLogin();
					return false;
				}
				return true;
			},
			tapMovableRZ(url) {
				if (!this.onCheckLogin()) {
					return false;
				}
				return new Promise((resolve, reject) => {
					app._get(
						"/client/peng-register/go-register", null,
						(result) => {
							let register = result.data
							uni.setStorageSync('register', register);
							if (register.settleState == 1) {
								this.$refs.toast.show({
									type: 'default',
									message: "您已是碰头人"
								})
								setTimeout(() => {
									this.$refs.toast.hide()
								}, 1000)
							} else if (register.settleState == 2) {
								this.$refs.toast.show({
									type: 'default',
									message: "入驻资料审核中"
								})
								setTimeout(() => {
									this.$refs.toast.hide()
								}, 1000)
							} else {
								app.navigationTo(url)
							}
						}, null, () => {
							resolve();
						}
					);
				});
			}
		},
	};
</script>

<style lang="scss" scoped>
	$mainSectionHeight: 696rpx; //首页section高度
	$tab-bar-height: 49px; //tabbar高度

	/* 在线链接服务仅供平台体验和调试使用，平台不承诺服务的稳定性，企业客户需下载字体包自行发布使用并做好备份。 */
	@font-face {
		font-family: "阿里妈妈数黑体 Bold";
		font-weight: 700;
		src: url("//at.alicdn.com/wf/webfont/SgHC0jUG4tj7/ZEFwfSy3i4WD.woff2") format("woff2"),
			url("//at.alicdn.com/wf/webfont/SgHC0jUG4tj7/J7pWWaFIPMfT.woff") format("woff");
		font-display: swap;
	}

	.top-bar {
		display: flex;
		align-items: center;
		padding: 0 20rpx;

		.logo {
			font-size: 32rpx;
			width: 180rpx;
			height: 64rpx;
			background: url("https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/new_logo.png") no-repeat;
			background-size: auto 100%;
		}
	}

	.location-wrapper {
		flex-grow: 1;
		padding: 0 20rpx;
		box-sizing: border-box;
		font-size: 28rpx;
		font-weight: 900;
		color: #232323;
		line-height: 37rpx;

		&::before {
			font-family: "dy-iconfont";
			content: "\e66e";
			font-size: 28rpx;
			padding-right: 10rpx;
			box-sizing: border-box;
		}
	}

	.container-main {
		min-height: calc(100vh - 130rpx);
		height: 100%;


		&::after {
			position: fixed;
			left: 0;
			right: 0;
			top: 0;
			content: '';
			width: 100%;
			height: 640rpx;
			background-image: url("https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/index/basic-bg2.png");
			background-repeat: no-repeat;
			background-size: cover;
		}

		/deep/.tui-navigation-bar {
			background: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/index/basic-bg2.png');
			background-repeat: no-repeat;
			background-size: 100% 640rpx;
			background-position: 0 0;
		}
	}

	.container {
		.tui-header {
			width: 100%;
			position: fixed;
			top: 0;
			padding: 0 12rpx;
			display: flex;
			align-items: center;
			height: 32px;
			transform: translateZ(0);
			z-index: 99999;
			box-sizing: border-box;
		}


		.category-tab {
			box-sizing: border-box;
			padding: 0 0 0 36rpx;
			position: sticky;
			position: -webkit-sticky;
			top: var(--header-height);
			z-index: 996;

			&.isFixed {
				background: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/index/basic-bg2.png');
				background-repeat: no-repeat;
				background-size: 100% 640rpx;
				background-position: 0 var(--header-height-f);
			}
		}

		.mescroll-body-main {
			position: relative;
			z-index: 2;
		}

		.main {
			// padding-bottom: calc(constant(safe-area-inset-bottom) + 10rpx);
			// padding-bottom: calc(env(safe-area-inset-bottom) + 10rpx);
			padding: 36rpx 32rpx 10rpx;
			box-sizing: border-box;

			.city-reminder {
				font-size: 26rpx;
				font-weight: 400;
				color: #FFBF12;
				line-height: 40rpx;
				box-sizing: border-box;
				padding: 28rpx 24rpx;
				background: #FFF8E5;
				border-radius: 40rpx;
			}

			.content-main {
				padding: 0 24rpx 10rpx;
			}

			.appraise-list {
				box-sizing: border-box;
				// padding: 0 24rpx 0;

				.appraise-item {
					box-sizing: border-box;
					padding-bottom: 37rpx;
					margin-top: 23rpx;

					&:first-child {
						margin-top: 0;
					}

					&.noBorder {
						border: none;
					}

					.advertising {
						width: 686rpx;
						height: 154rpx;
						border-radius: 40rpx;
						margin-top: 72rpx;
						box-sizing: border-box;
						padding: 25rpx 0 25rpx 567rpx;
						background: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/free-purchase/free-1.png');
						background-repeat: no-repeat;
						background-size: cover;

						.adv-image {
							animation: scaleAnimation 0.4s ease 0s infinite alternate;
							width: 104rpx;
							height: 104rpx;
						}
					}
				}

				.refer-box {
					display: flex;
					margin-top: 27rpx;
					box-sizing: border-box;
					padding-left: 106rpx;
					align-items: center;
				}

				.refer {
					flex-shrink: 0;
					font-size: 24rpx;
					font-weight: 400;
					color: #999B9B;
					line-height: 33rpx;
				}

				.order {
					box-sizing: border-box;
					display: flex;
					align-items: center;

					.accompany-profile {
						width: 42rpx;
						height: 42rpx;
						border-radius: 50%;
						flex-shrink: 0;
						margin-right: 7rpx;
						position: relative;

						.avatarUrl {
							width: 100%;
							height: 100%;
							border-radius: 50%;
						}
					}

					.user-name {
						font-size: 24rpx;
						font-weight: 400;
						color: #999B9B;
						line-height: 33rpx;
					}

					.order-per {
						max-width: 80%;
						font-size: 28rpx;
						font-weight: 900;
						color: #222222;
						line-height: 44rpx;
					}

					.order-time {
						font-size: 24rpx;
						font-weight: 400;
						color: #222222;
						line-height: 44rpx;
						margin-top: 4rpx;
					}
				}

				.delete {
					width: 100rpx;
					height: 36rpx;
					background: #FFFFFF;
					border-radius: 20rpx;
					border: 2rpx solid #E3E9E5;
					font-size: 24rpx;
					font-weight: 400;
					color: #999B9B;
					line-height: 36rpx;
					text-align: center;
					margin-top: 26rpx;
					margin-left: auto;
				}
			}

			scroll-view {
				white-space: nowrap;
			}

			.banner {
				margin-bottom: 32rpx;
			}

			.category-tab {
				.menu-item {
					display: inline-block;
					width: 132rpx;
					height: 128rpx;
					background: #FFFFFF;
					border-radius: 12rpx;
					margin: 32rpx 12rpx 24rpx 0;
					box-shadow: 2rpx 3rpx 11rpx 0rpx rgba(224, 224, 224, 0.5);
					font-size: 28rpx;
					font-weight: 900;
					color: #BBBCBB;
					line-height: 37rpx;

					&.menu-item-active {
						background: linear-gradient(144deg, #CCFA2F 0%, #ABF61A 55%, #A7F517 100%);
						color: #101010;
					}

					.menu-item-box {
						display: flex;
						justify-content: center;
						align-items: center;
						flex-direction: column;
						height: 100%;
					}

					.menu-image-wrapper {
						height: 60rpx;
						margin-bottom: 3rpx;

						.icon {
							height: 100%;
						}
					}

					.name {}
				}
			}
		}
	}

	.guidance {
		position: absolute;
		left: 52rpx;
		top: 600rpx;
		width: 646rpx;
		height: 239rpx;
		background-image: url("https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/index/overlay-k.png");
		background-repeat: no-repeat;
		background-size: 100%;
		z-index: 10002;
	}

	.popup-comment {
		box-sizing: border-box;
		padding: 48rpx 48rpx 142rpx;
		background: #FFFFFF;
		border-radius: 40rpx 40rpx 0px 0px;

		.header {
			display: flex;
			align-items: center;
			justify-content: space-between;
			box-sizing: border-box;
			padding-bottom: 41rpx;

			.title {
				font-size: 32rpx;
				font-weight: 900;
				color: #282D2D;
				line-height: 45rpx;
			}

			.close {
				font-size: 22rpx
			}
		}
	}

	.foot {
		box-shadow: 0px 0 9rpx 0px rgba(198, 204, 202, 0.56);
		position: absolute;
		background: #FFFFFF;
		width: 100vw;
		bottom: 0;
		left: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);

		.foot-box {
			box-sizing: border-box;
			padding: 34rpx 36rpx;
			background: #FFFFFF;

			&.foot-input-pop {
				position: relative;
				transition: bottom 300ms ease-out 0ms, -webkit-transform 300ms ease-out 0ms, transform 300ms ease-out 0ms;
				transform-origin: 50% 50%;
			}

			.foot-input {
				box-sizing: border-box;
				padding: 12rpx 36rpx;
				width: 100%;
				height: 64rpx;
				background: #F6F8F7;
				border-radius: 39rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #999B9B;
				line-height: 40rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.input-text {
					flex: 1;
				}

				.icon-xingzhuangjiehebeifen {
					color: #282D2D;
					font-size: 40rpx;
					padding-left: 30rpx;
				}
			}
		}
	}

	.delete-pop-menu {
		background: #FFFFFF;
		box-sizing: border-box;
		padding: 0 25rpx 0;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		position: relative;

		.menu-list {
			padding: 38rpx 0;
			position: relative;
			font-size: 32rpx;
			font-weight: 400;
			color: #282D2D;
			line-height: 45rpx;
			border-bottom: 2rpx solid #E3E9E5;
			// display: flex;
			text-align: center;

			&.delete {
				color: #FF4664;
			}

			&:last-child {
				border: none;
			}

			.dy-iconfont {
				margin-right: 25rpx;
			}
		}
	}

	.free-purchase-pop {
		position: relative;

		.title {
			font-family: "阿里妈妈数黑体 Bold" !important;
			font-size: 48rpx;
			color: #fff;

			.title1 {
				line-height: 57rpx;
				text-align: center;
				margin-bottom: 17rpx;
			}

			.title2 {
				text-align: center;
			}
		}

		.purchase-con {
			margin-top: 43rpx;
			width: 660rpx;
			height: 564rpx;
			border-radius: 40rpx;
			background-image: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/free-purchase/free-purchase.png');
			background-repeat: no-repeat;
			background-size: cover;
			margin-bottom: 77rpx;
		}

		.purchase-btn {
			padding: 0 33rpx;
			display: flex;
			margin-bottom: 32rpx;

			.rule {
				width: 228rpx;
				height: 88rpx;
				background: #F6F8F7;
				border-radius: 75rpx;
				border: 4rpx solid #FFBF12;
				font-weight: 900;
				font-size: 40rpx;
				color: #FF4E04;
				line-height: 88rpx;
				text-align: center;
				margin-right: 24rpx;
			}

			.purchase-now {
				width: 330rpx;
				height: 115rpx;
				background-image: url('https://pengtou-1322587508.cos.ap-shanghai.myqcloud.com/static/images/free-purchase/purchase-now.png');
				background-repeat: no-repeat;
				background-size: cover;
				position: relative;

				.ttt {
					position: absolute;
					top: -16rpx;
					right: 0;
					width: 123rpx;
					height: 36rpx;
					background: #FFBF12;
					border-radius: 20rpx 0rpx 20rpx 0rpx;
					font-weight: 600;
					font-size: 20rpx;
					color: #FFFFFF;
					line-height: 36rpx;
					text-align: center;
				}
			}
		}

		.count-down {
			font-weight: 600;
			font-size: 26rpx;
			color: #FFFFFF;
			line-height: 37rpx;
			text-align: center;
		}

		.free-purchase-pop-close {
			position: absolute;
			top: 21rpx;
			right: 0;
			width: 64rpx;
			height: 64rpx;
			border: 1rpx solid #FFFFFF;
			border-radius: 50%;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 22rpx;
			color: #F6F8F7;
		}
	}


	.btn-submit {
		position: fixed;
		width: calc(100% - 253rpx * 2);
		bottom: calc(constant(safe-area-inset-bottom) + 184rpx);
		bottom: calc(env(safe-area-inset-bottom) + 184rpx);
		left: 50%;
		transform: translateX(-50%);
		z-index: 10;
		border-radius: 50rpx;
		opacity: 1;
		transition: all 1s;

		&.can-swip-submit {
			opacity: 0.4;
			bottom: -100rpx;
		}
	}

	.image-box {
		position: relative;
		width: 136rpx;
		height: 140rpx;

		.ruzhu-index-btn {
			width: 146rpx;
			height: 155rpx;
		}

		.free-index-ani {
			position: absolute;
			z-index: 3;
			width: 134rpx;
			height: 132rpx;

			// transform: translate(0px, 0px);
			.jump1 {
				width: 32rpx;
				height: 31rpx;
				position: absolute;
				left: 21rpx;
				top: 2rpx;
				// animation: jump infinite 2s ease;
				animation: jump 4s ease 0s infinite;
			}

			.jump2 {
				width: 15rpx;
				height: 15rpx;
				position: absolute;
				left: 88rpx;
				top: 0;
				// animation: jump2 2s ease 2s infinite;
			}

			.jump3 {
				width: 36rpx;
				height: 25rpx;
				position: absolute;
				left: 98rpx;
				top: 95rpx;
			}

			.jump4 {
				width: 15rpx;
				height: 15rpx;
				position: absolute;
				left: 0;
				top: 72rpx;
				animation: jump 3s ease 3s infinite;
			}
		}

		.free-index-btn {
			position: absolute;
			z-index: 2;
			width: 100rpx;
			height: 37rpx;
			bottom: 0;
			left: 50%;
			margin-left: calc(-100rpx / 2);
		}

		.free-index {
			position: absolute;
			z-index: 1;
			width: 136rpx;
			height: 118rpx;
		}
	}

	@keyframes scaleAnimation {
		0% {
			transform: scale(0.9);
		}

		100% {
			transform: scale(1.1);
		}
	}
</style>